﻿using System;
using System.Web.UI;
using SGRapidForm.Foundation.Service.Interface;
using SGRapidForm.Common;
using DevExpress.Web.ASPxMenu;
using System.Xml;
using SGRapidForm.Foundation.Entity;

namespace SGRapidForm.Foundation
{
    public partial class FoundationDetail : System.Web.UI.Page
    {
        private IFoundationService _foundationService = ServiceProxyFactory.Create<IFoundationService>("foundationservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
        }

        /// <summary>
        /// 菜单项绑定事件 - 实现操作权限控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void menuHeader_ItemDataBound(object sender, MenuItemEventArgs e)
        {
            IHierarchyData itemHierarchyData = (IHierarchyData)e.Item.DataItem;
            XmlElement element = (XmlElement)itemHierarchyData.Item;
        }

        /// <summary>
        /// 新增保存
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SaveForAdd(FoundationEntity f)
        {
            return _foundationService.AddFoundation(f);

        }

        /// <summary>
        /// 获取基础资料明细
        /// </summary>
        /// <param name="keyid">用户Keyid</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public FoundationEntity GetFoundationByKeyid(string keyid)
        {
            return _foundationService.GetFoundationByKeyid(keyid);
        }

        /// <summary>
        /// 编辑保存
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SaveForEdit(FoundationEntity f)
        {
            bool ret = _foundationService.UpdateFoundation(f);
            return ret;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="keyid">用户Keyid</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool Delete(string keyid)
        {
            return _foundationService.DeleteFoundation(keyid);
        }
    }
}